{extend name="layout" /}
{block name="content"}
{php}
$url_param = input('param.');

{/php}
<div class="row">
	<div class="col-md-12">
		<div class="box">
			<div class="box-header bg-gray-lighter">
				<h3 class="box-title">{$title}</h3>
			</div>
			<div class="tab-content">
				<div class="tab-pane active" id="tab1">
					<div class="box-body">
						<form class="form row" id="form" name="form" action="" method="post" parent_reload="1">
							<input type="hidden" name="id" value="{$data.id}" />
							<div class="form-group col-md-12 col-xs-12 col-md-12 col-xs-12">
								<label class="col-md-12">{:lang('所属上级字段')}</label>
								<div class="col-sm-12">
									<select class="form-control select2" name="pid" style="width:100%;">
										<option value="0">{:lang('顶级字段')}</option>
							                                		{volist name="fields" id="f"}
										<option value="{$f.id}">{$f.title_display|raw}</option>
							                                		{/volist}
									</select>
								</div>
							</div>
							<!--<div class="form-group col-md-12 col-xs-12 col-md-12 col-xs-12">
								<label class="col-md-12">{:lang('选择表名')}</label>
								<div class="col-sm-12">
									<select class="form-control select2" name="" style="width:100%;" id="changetable">
										<option value="">{:lang('选择表名')} -> {:lang('选择字段')}</option>
                                		{volist name="biao_data" id="vo"}
										<option value="{$vo['name']}">{$vo['name']}（{$vo['info']}）</option>
                                		{/volist}
									</select>
								</div>
							</div>-->
							<!--<div class="form-group col-md-12 col-xs-12">
								<label class="col-md-12">{:lang('选择字段')}</label>
								<div class="col-md-12">
									<select class="form-control select2" name="" style="width:100%;" id="changefield">
										<option value="">{:lang('先选择表名')}</option>
									</select>
								</div>
							</div>-->
							<div class="form-group col-md-12 col-xs-12">
								<label class="col-md-12">{:lang('字段')}</label>
								<div class="col-md-12">
									<input class="form-control" type="text" id="field_name" data-rule="required;" name="fieldName" value="{$data.fieldName?:''}" placeholder="{if $type == 1}{:lang('建议字段名和数据库一样')}，{:lang('数据库没有可以自定义')}{else /}{:lang('字段名称必须是英文')}{/if}">
								</div>
							</div>
							<div class="form-group col-md-12 col-xs-12">
								<label class="col-md-12">{:lang('说明')}</label>
								<div class="col-md-12">
									<input class="form-control" type="text" id="info" data-rule="required;" name="info" value="{$data.info?:''}" placeholder="{:lang('字段说明')}">
								</div>
							</div>
							<div class="form-group col-md-12 col-xs-12">
								<label class="col-md-12">{:lang('数据类型')}</label>
								<div class="col-md-12">
									<select class="form-control select2" name="dataType" style="width:100%;" id="dataType">
										<option value="1" {notempty name="$data.dataType"}{if $data.dataType eq '1'}selected="selected"{/if}{/notempty} >Integer[{:lang('整数')}]</option>
										<option value="2" {notempty name="$data.dataType"}{if $data.dataType eq '2'}selected="selected"{/if}{/notempty} >String[{:lang('字符串')}]</option>
										<option value="3" {notempty name="$data.dataType"}{if $data.dataType eq '3'}selected="selected"{/if}{/notempty} >Boolean[{:lang('布尔')}]</option>
										<option value="4" {notempty name="$data.dataType"}{if $data.dataType eq '4'}selected="selected"{/if}{/notempty} >Enum[{:lang('枚举')}]</option>
										<option value="5" {notempty name="$data.dataType"}{if $data.dataType eq '5'}selected="selected"{/if}{/notempty} >Float[{:lang('浮点数')}]</option>
										<option value="6" {notempty name="$data.dataType"}{if $data.dataType eq '6'}selected="selected"{/if}{/notempty} >File[{:lang('文件')}]</option>
										<option value="7" {notempty name="$data.dataType"}{if $data.dataType eq '7'}selected="selected"{/if}{/notempty} >Mobile[{:lang('手机号')}]</option>
										<option value="8" {notempty name="$data.dataType"}{if $data.dataType eq '8'}selected="selected"{/if}{/notempty} >Object[{:lang('对象')}]</option>
										<option value="9" {notempty name="$data.dataType"}{if $data.dataType eq '9'}selected="selected"{/if}{/notempty} >Array[{:lang('数组')}]</option>
										<option value="10" {notempty name="$data.dataType"}{if $data.dataType eq '10'}selected="selected"{/if}{/notempty} >Email[{:lang('邮箱')}]</option>
										<option value="11" {notempty name="$data.dataType"}{if $data.dataType eq '11'}selected="selected"{/if}{/notempty} >Date[{:lang('日期')}]</option>
										<option value="12" {notempty name="$data.dataType"}{if $data.dataType eq '12'}selected="selected"{/if}{/notempty} >Url</option>
										<option value="13" {notempty name="$data.dataType"}{if $data.dataType eq '13'}selected="selected"{/if}{/notempty} >IP</option>
									</select>
								</div>
							</div>
							<div class="form-group col-md-12 col-xs-12">
								<label class="col-md-12">{:lang('默认值')}</label>
								<div class="col-md-12">
									<input class="form-control" type="text" name="default" value="{$data.default}" placeholder="{:lang('默认值')}">
								</div>
							</div>
							<div class="form-group col-md-12 col-xs-12">
								<label class="col-md-12">Mock{:lang('测试数据')}</label>
								<div class="col-md-12">
									<input class="form-control" type="text" name="mock" value="{$data.mock}" placeholder="mock{:lang('测试数据')}">
								</div>
							</div>
							<div class="form-group col-md-12 col-xs-12">
								<label class="col-md-12">{:lang('是否必填')}</label>
								<div class="col-md-12">
									<select class="form-control select2" name="isMust" style="width:100%;">
										<option value="1" {if $data.isMust eq '1'}selected="selected"{/if} >{:lang('必填')}</option>
										<option value="0" {if $data.isMust eq '0'}selected="selected"{/if} >{:lang('选填')}</option>
									</select>
								</div>
							</div>
							<!--<div class="form-group col-md-12 col-xs-12">
								<label class="col-md-12">规则细节</label>
								<div class="col-md-12">
									<textarea class="form-control" style="resize:none;height:155px;" name="range" placeholder="请输入符合要求的JSON字符串">{$data.range?:''}</textarea>
								</div>
								<div class="col-sm-3"> 例如：{"min":"2","max":"10"}<br />
									Integer[整数类型] Float[浮点数]<br />
									验证字段的值 >= 2, <= 10<br />
									String[字符串类型] Array[数组]<br />
									验证字段的值的最小长度2，最大长度10 </div>
							</div>-->

							<div class="form-group col-md-12 col-xs-12">
								<div class="col-xs-12">
									<button class="btn btn-minw btn-primary" type="submit">{:lang('提交')}</button>
									<button class="btn btn-default btn-flat" type="button" onClick="closelayer()"> {:lang('关闭')}
									</button>
                                </div>
                           </div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
{/block}

{block name="script"} 
<script type="text/javascript">
$(function(){


    $('#changetable').change(function(){
    	var biao_name = $(this).val();
		$('#changefield').empty();	//删除原来的列表
    	$.ajax({
    	    url: "{:url('getInfo')}", //请求url
    	    type: "post",  //请求的类型
    	    dataType: "json",  //数据类型
    	    data: {'name':biao_name}, //发送到服务器的数据
    	    success:function(data) { //成功后执行
    	    	var html = '<option value="">先选择表名</option>';
    	    	$('#changefield').append(html);
    	        for (var i = 0; i < data.data.length; i++) {
    	        var	html_list = '<option value="'+ data.data[i].name +'">'+ data.data[i].name +'【'+ data.data[i].info + '。类型：'+ data.data[i].type +'】</option>';
    	        	$('#changefield').append(html_list);
    	        }
    	    }
    	});
    });
    $('#changefield').change(function(){
		var text = $("#changefield option:selected").text();
		$('#info').val(text);
    	var ziduan_name = $(this).val();
    	$('#field_name').val(ziduan_name);
    });
	var $field_mock = $('input[name=mock]');
	$('#dataType').change(function(){
    	var val = $(this).val();
    	if(val == 1){
			$field_mock.val(100);
		}else if(val == 3){
			$field_mock.val(1);
		}else if(val == 5){
			$field_mock.val(11.11);
		}else if(val == 10){
			$field_mock.val('m22543@163.com');
		}else if(val == 11){
			$field_mock.val('2020-05-19');
		}else if(val == 12){
			$field_mock.val('http://111.229.13.202:3210/uploads/images/20190920/cb424395d05e4ca03bb5c5976f4aa600.jpg');
		}else if(val == 6){
			$field_mock.val('http://111.229.13.202:3210/uploads/images/20190923/43ef6824719114f954e8f48bfa924a2a.jpeg.tar.gz');
		}else if(val == 7){
			$field_mock.val('13333333333');
		}
		else{
			$field_mock.val('这里是返回的文字字符串');
		}
    });
})

function closelayer() {
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	parent.layer.close(index);
}

</script> 
{/block} 